package com.weicai.hive.udf;

import org.apache.hadoop.hive.ql.exec.UDF;
import org.apache.hadoop.io.Text;

import com.weicai.caesar.CaesarUtil;
import com.weicai.hive.util.PIDValidator;

public class PIDValidateUDF extends UDF{

	public Text evaluate(String str) {
		str=decode(str);
		Text text = new Text("0");
		if(str==null || str.length()==0){
			return text;
		}
		if(PIDValidator.isValidIDCard(str)){
			text.set("1");
		}
		return text;
		
	}
    private static String decode(String s){
    	if(CaesarUtil.isEncrypted(s)){
    		s=CaesarUtil.decode(s);
    	}
    	return s;
    }	
	
}
